//package binomialHeapLeeor;

import java.util.Arrays;
import java.util.Random;

public class Tester {
	public static void main(String[] args) {
		final int N = 100;	//Change N for larger heap	
		BinomialHeap heap1 = new BinomialHeap();
		BinomialHeap heap2 = new BinomialHeap();
		int num,calcSum;
		int [] roots;
		Random iter = new Random();

		int [] list = new int[2*N]; 

		for(int i=0;i<N;i++){ //create heap1
			num = iter.nextInt(10*N);
			heap1.insert(num);
			list[i] = num;
		}
		for(int i=0;i<N;i++){ //create heap2
			num = iter.nextInt(10*N);
			heap2.insert(num);
			list[i+N] = num;
		}
		Arrays.sort(list); //list contains all the elements in both heaps, sorted by order
		heap1.meld(heap2); // melding the heaps

		for (int i=0;i<2*N;i++){
			if (heap1.findMin()!=list[i]){
				System.out.println("TEST i="+i+" minimum item - FAILED"); //test min item compared to ordered list
				break;}
			if (heap1.size()!= 2*N-i){
				System.out.println("TEST i="+i+" size - FAILED"); //test size
				break;}
			if (!heap1.isValid()){
				System.out.println("TEST i="+i+" isValid - FAILED"); //test validity
				break;}	
			roots = heap1.treesRanks();
			calcSum = 0;
			for (int j=0;j<roots.length;j++) 
			calcSum += Math.pow(2,roots[j]);
			if (calcSum!=heap1.size()){
				System.out.println("TESTi="+i+" treeRanks - FAILED"); //test amount of roots by calc. base-2 repr. of size 
				break;}	
			System.out.println("TESTS i="+i+" PASSED");
			heap1.deleteMin();
		}

	}
}

